function getAjax() {
	var req = false;
	try {
		req = new XMLHttpRequest();
	} catch(err) {
		try {
			req = new ActiveXObject("Msxml12.XMLHTTP");
		} catch(err) {
			try {
				req = new ActiveXObject("Microsoft.XMLHTTP");
			} catch(err) {
				req = false;
			}
		}
	}
	return req;
}

function sendReply(message) {
	var thePage = 'postFeed.php?message=' + message;
	myReq.open("GET", thePage, true);
	myReq.onreadystatechange = processPost;
	myReq.send(null);
}

function processPost() {
	if(myReq.readyState == 4) {
		if(myReq.status == 200) {
			XMLdoc = myReq.responseXML;
			var temp = XMLdoc.getElementsByTagName("RESULT")[0].firstChild.nodeValue;
		}
	} else {
		// loading
	}
}

function getNews() {
	var thePage = 'fetchNews.php';
	myReq.open("GET", thePage, true);
	myReq.onreadystatechange = processNews;
	myReq.send(null);
}

var newReq = getAjax();

function getFeed() {
	var thePage = 'fetchFeed.php';
	newReq.open("GET", thePage, true);
	newReq.onreadystatechange = processFeed;
	newReq.send(null);

}

function processNews() {
	if(myReq.readyState == 4) {
		if(myReq.status == 200) {
			XMLdoc = myReq.responseXML;
			var txt = "";
			var news = XMLdoc.getElementsByTagName("ANNOUNCEMENT");
			document.getElementById('content').innerHTML = "";
			document.getElementById('content').innerHTML += '<div id="announceKnop" class="knop" onclick="window.open(\'postAnnouncement.html\', \'announce\', \'width=500, height=400\')">++Ik wil  meer bullshit++</div>';
			for( i = news.length - 1; i > -1; i--) {
				txt = "<div class='announcement box' ><h1>" + news[i].getElementsByTagName("TITLE")[0].firstChild.nodeValue + "</h1> posted by " + news[i].getElementsByTagName("POSTER")[0].firstChild.nodeValue + "<br />" + news[i].getElementsByTagName("MESSAGE")[0].firstChild.nodeValue + "</div>";
				txt = txt.replace("[", "<");
				txt = txt.replace("]", ">");
				document.getElementById('content').innerHTML += txt;
			}
			$('#linkNaarBlog').addClass('globalNavSelected');
			$('#linkNaarHome').removeClass('globalNavSelected');
			
		}
	} else {
		// loading
	}
}

function processFeed() {
	if(newReq.readyState == 4) {

		if(newReq.status == 200) {
			XMLdoc = newReq.responseXML;
			var txt = "";
			var posts = XMLdoc.getElementsByTagName("POST");
			for( i = 0; i < posts.length; i++) {
				txt += "<b>" + posts[i].getElementsByTagName("POSTER")[0].firstChild.nodeValue + " " + posts[i].getElementsByTagName("DT")[0].firstChild.nodeValue + "</b><br />" + posts[i].getElementsByTagName("MESSAGE")[0].firstChild.nodeValue + "<br />";
			}

			document.getElementById('feed').innerHTML = txt;
			getFeed();
		}
	} else {
		// loading
	}
}